//
//  FR_Attendance_TableViewCell.m
//  FaceRecognition
//
//  Created by zz on 17/7/18.
//  Copyright © 2017年 Sylar. All rights reserved.
//

#import "FR_Attendance_TableViewCell.h"

@interface FR_Attendance_TableViewCell()

@property (nonatomic, strong) UILabel *classesLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *stateLabel;

@end

@implementation FR_Attendance_TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        CGFloat rate = SCREENWIDTH / 375;
        
        for (int i = 0; i < 4; i++) {
            
            UILabel *label = [[UILabel alloc] init];
            label.font = [UIFont systemFontOfSize:15];
            label.textAlignment = NSTextAlignmentCenter;
            
            label.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
            [self.contentView addSubview:label];
            label.text = @"这是label";
            if ( i == 0) {
                _classesLabel = label;
            }else if (i == 1){
                _nameLabel = label;
            }else if (i == 2){
                _dateLabel = label;
            }else {
                _stateLabel = label;
            }
        }
        
        _classesLabel.frame = CGRectMake(15 * rate, 0, 99 * rate, 44);
        _nameLabel.frame = CGRectMake(CGRectGetMaxX(_classesLabel.frame), 0, 82 * rate, 44);
        _dateLabel.frame = CGRectMake(CGRectGetMaxX(_nameLabel.frame), 0, 82 * rate, 44);
        _stateLabel.frame = CGRectMake(CGRectGetMaxX(_dateLabel.frame), 0, 82 * rate, 44);
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, 43.5, SCREENWIDTH - 15, 0.5)];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#dedede"];
        [self.contentView addSubview:lineView];
        
        self.contentView.backgroundColor  = [UIColor whiteColor];
    }
    
    return self;
}

- (void)setModel:(FR_Attendance_Model *)model {
    
    _model = model;
    
    _classesLabel.text = model.classname;
    _nameLabel.text = model.studentname;
    _dateLabel.text = model.zptime;
    
    
    if (model.arrival == 1) {
        
        _stateLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
    }else if (model.arrival == 4) { //正常 显示灰色
        
        _stateLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        
    }else {
        
        _stateLabel.textColor = [UIColor colorWithHexString:@"#f55f5f"];
    }

    
    
    NSString *stateStr;
    
    switch (model.arrival) {
        case 0:
            stateStr = @"旷课";
            break;
        case 1:
            stateStr = @"正常";
            break;
        case 2:
            stateStr = @"迟到";
            break;
        case 3:
            stateStr = @"请假";
            break;
        case 4:
            stateStr = @"休息";
            break;
        default:
            break;
    }
    
    _stateLabel.text = stateStr;
    
    _dateLabel.text = model.date;
}

@end
